home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 483 / mkrscsrc / addsub.c next >
Encoding:
C/C++ Source or Header  |  1990-04-26  |  6.5 KB  |  258 lines

  1. #include "stdio.h"
  2. #include "gemdefs.h"
  3. #include "obdefs.h"
  4. #include "osbind.h"
  5. #include "mkrsc.h"
  6. #include "globals.h"
  7.  
  8.  
  9. /*
  10.     You now want to move the object from the left hand menu pointed
  11.     to by objptr to the tree structure inwindow.  It must be added to the
  12.     array of objects in thfrontwin->inwindow->objt[], and count
  13.      incremented.  Then you must link it to the other objects in the
  14.      array with objc_add().  You link it to the parent object pointed 
  15.     to by the index number 'nindex'.  'oindex' points to the object that
  16.      was selected from the onleft tree.  In the case of titles in menu
  17.     bars, they are always linked to object 2 in tree.
  18. */    
  19.  
  20. int    add_tosub(objptr,nindex,oindex,x,y)
  21.     OBJECT        *objptr;
  22.     int            nindex, oindex, x, y;
  23. {
  24.     int result, num, obj_type, xoff, yoff;
  25.     int cx,cy,cw,ch;
  26.     OBJECT *objptr2;
  27.     objtreeptr thetree;
  28.     windowptr    thewin;
  29.  
  30.     thewin = thefrontwin;
  31.     thetree = thefrontwin->inwindow;
  32.  
  33.     if (onleft[oindex].ob_type == G_TITLE)
  34.     {
  35. /*    make sure you are moving a title to the menu bar    */
  36.         result = objc_find(thetree->objt,1,0,x,y);
  37.         if (result == 1)    
  38.         {    in_ttl(x,y,0);
  39.             draw_inwind(thefrontwin,1);
  40.         }
  41.         return;
  42.     }
  43.  
  44. /*    bail out if its a menu tree and the icon is not being dragged to a
  45.     menubox
  46. */
  47.  
  48.     if(thefrontwin->inwindow->kind[0] == TMENU
  49.          && nindex != thefrontwin->inwindow->mbox)
  50.                 return;
  51.  
  52.  
  53. /* copy the icon into the object tree array in thetree struct */
  54.  
  55.     thetree->objt[++thetree->count] = *objptr;
  56.  
  57. /* handy pointer    */
  58.     num = thetree->count;
  59.  
  60. /* copy the oject index from onleft tree into 'kind'    */
  61.  
  62.     thetree->kind[num] = oindex;
  63.     thetree->name[num][0] = NULL;
  64.  
  65. /* set up a handy ptr */
  66.     objptr2 = &thetree->objt[thetree->count];
  67.  
  68. /* clear the pointers for the new object  */
  69.  
  70.     objptr2->ob_next = -1;
  71.     objptr2->ob_head = -1;
  72.     objptr2->ob_tail = -1;
  73.  
  74. /* get the object type of object coming in    */
  75.  
  76.     obj_type = thetree->objt[num].ob_type;
  77.  
  78. /* set its position */
  79.  
  80.         objc_offset(thetree->objt, nindex, &xoff, &yoff); 
  81.         x -= xoff;
  82.         y -= yoff;
  83.         objptr2->ob_y = y;
  84.         objptr2->ob_x = x;
  85.         if(snap || (thefrontwin->inwindow->kind[0] == TMENU))
  86.  
  87.         {    objptr2->ob_x += gl_wchar/2;
  88.             objptr2->ob_x &= 0xFFF8;
  89.             objptr2->ob_y += gl_hchar/2;
  90.             objptr2->ob_y &= (0xFFFF - gl_hchar + 1);
  91.         }
  92.  
  93.     if(thefrontwin->inwindow->kind[0] == TMENU)
  94.         objptr2->ob_x = 0;
  95.     
  96.  
  97. /* make it a last object  */
  98.  
  99.     objptr2->ob_flags |= LASTOB;
  100.  
  101. /* copy any necessary structures to the newtree structure  */
  102.  
  103.  
  104.     switch (obj_type)
  105.     {
  106.         case G_TEXT        :
  107.         case G_BOXTEXT    :
  108.         case G_FTEXT    :
  109.         case G_FBOXTEXT    : 
  110.             thetree->ti[num] = *((TEDINFO *)(onleft[oindex].ob_spec));
  111.             thetree->objt[num].ob_spec = (char *)&thetree->ti[num];
  112.             strcpy(thetree->strings[num],
  113.                 ((TEDINFO *)(onleft[oindex].ob_spec))->te_ptext);
  114.             thetree->ti[num].te_ptext = thetree->strings[num];
  115.             strcpy(thetree->template[num],
  116.                 ((TEDINFO *)(onleft[oindex].ob_spec))->te_ptmplt);
  117.             thetree->ti[num].te_ptmplt = thetree->template[num];
  118.             strcpy(thetree->valid[num],
  119.                 ((TEDINFO *)(onleft[oindex].ob_spec))->te_pvalid);
  120.             thetree->ti[num].te_pvalid = thetree->valid[num];
  121.             break;
  122.         case G_BUTTON    :
  123.         case G_STRING    :
  124.         case G_TITLE    :
  125.             strcpy(thetree->strings[num], onleft[oindex].ob_spec);
  126.             thetree->objt[num].ob_spec = thetree->strings[num];
  127.             break;
  128.         case G_ICON        :
  129.             thetree->icblk[num] = *((ICONBLK *)(onleft[oindex].ob_spec));
  130.             thetree->objt[num].ob_spec = (char *)&thetree->icblk[num];
  131.             strcpy(thetree->strings[num],
  132.                 ((ICONBLK *)(onleft[oindex].ob_spec))->ib_ptext);
  133.             thetree->icblk[num].ib_ptext = thetree->strings[num];
  134.             break;
  135.     }        
  136.  
  137.  
  138. /* link the new object into its parent   */
  139.  
  140.     if(thefrontwin->inwindow->kind[0] == TMENU)
  141.         result = objc_add(thetree->objt,
  142.                             thefrontwin->inwindow->mbox,thetree->count);
  143.     else
  144.         result = objc_add(thetree->objt,nindex,thetree->count);
  145.     
  146. /* reset the LASTOB for the previous object in tree  */
  147.  
  148.     thetree->objt[num-1].ob_flags &= ~LASTOB;
  149.     
  150. /* redraw the icons in the window object tree  */
  151.  
  152. /*    draw_inwind(thefrontwin,0);    */
  153.     objc_draw(thetree->objt,nindex,10,thefrontwin->work.g_x,
  154.                         thefrontwin->work.g_y,
  155.                         thefrontwin->work.g_w,thefrontwin->work.g_h);
  156. }
  157.  
  158. /*    Clicks is the number of button clicks and result is the object
  159.     number of the object the mouse was over in the tree that was
  160.     active in the right window
  161. */
  162.  
  163. hand_subtree(clicks,result,mousex,mousey)
  164.     int clicks, result, mousex, mousey;
  165. {
  166.     int newstate,i;
  167.     OBJECT *inwinptr;
  168.     int mx, my, mstate, kbdstate;
  169.     int tparent, bparent, next;
  170.  
  171. /*    Set up handy pointer to right window object tree    */
  172.  
  173.         inwinptr = thefrontwin->inwindow->objt;
  174.  
  175. /*    tparent is parent of titles and bparent parent of menu boxes
  176.     These are used only for menu object trees...  see below
  177.  
  178. */
  179.  
  180.         tparent = 2;
  181.         bparent = inwinptr[1].ob_next;
  182.  
  183.         if (clicks == 2)
  184.         {
  185.             dbl_clsub(result);
  186.         }
  187.         else        /*  clicks = 1   */
  188.         {
  189.         /*    deselect all selected objects    */
  190.  
  191.             for(i=0;i<(thefrontwin->inwindow->count + 1);i++)
  192.                 if( (inwinptr[i].ob_state & SELECTED) && (result != i) )
  193.                     inwinptr[i].ob_state &= ~SELECTED;
  194.  
  195. /*    Toggle state of the selected icon and redraw tree
  196. */
  197.             inwinptr[result].ob_state ^= SELECTED;
  198.  
  199. /*     If it is a menu tree, and a title has been clicked
  200.     figure out which menubox (mbox) is under it and
  201.     display drop down menu box as well (see draw_inwind())
  202. */
  203.  
  204.                 if( (thefrontwin->inwindow->kind[0] == TMENU)
  205.                     && (inwinptr[result].ob_type == G_TITLE) )
  206.                 {    next = inwinptr[bparent].ob_head;
  207.                     for (i=0;i<result-tparent;i++)
  208.                         {    thefrontwin->inwindow->mbox    =next;
  209.                             next = inwinptr[next].ob_next;
  210.                         } 
  211.                 }
  212.  
  213.     /* check if the mouse button is being held down    */
  214.  
  215.         graf_mkstate(&mx, &my, &mstate, &kbdstate);
  216.         if(mstate == 1)
  217.             drag_right(result,mousex,mousey);  /* see drag.c   */
  218.  
  219.         }    /* end of else    */
  220.             if( (result == 0)
  221.                 || (thefrontwin->inwindow->kind[0] == TMENU) )
  222.                 draw_inwind(thefrontwin,1);
  223.             else
  224.                 draw_inwind(thefrontwin,0);
  225.  
  226. }
  227.  
  228. /*    'result' is the object in the inwindow tree    */
  229.         
  230. int dbl_clsub(result)
  231.     int result;
  232. {
  233.     int obj_type;
  234.  
  235.     obj_type = thefrontwin->inwindow->objt[result].ob_type;
  236.  
  237.     switch (obj_type)
  238.     {
  239.         case G_TEXT        :
  240.         case G_BOXTEXT    :
  241.         case G_FTEXT    :
  242.         case G_FBOXTEXT    :    do_tist(result);
  243.                               break;
  244.         case G_BUTTON    :
  245.         case G_STRING    :
  246.         case G_TITLE    :    do_buttont(result);
  247.                             break;
  248.         case G_ICON        :
  249.                             break;
  250.         case G_BOXCHAR    :    do_boxct(result);
  251.                             break;
  252.         case G_BOX        :
  253.         case G_IBOX        :    do_boxt(result);
  254.                             break;
  255.     }
  256. }
  257.  
  258.